// 计算函数的优化
// summation  成为一个记忆函数，用闭包
function summation() {
    let map = new Map()  // key  value->曾经计算过
    return function (target) {
        if(map.has(target)) {
            console.log('为您缓存了。。。');
            return map.get(target);
        }
        let sum = 0;
        for (var i = 1; i <= target; i++) {
            sum += i;
        }
        map.set(target,sum);
        return sum;
    }
}

const summationWithMemo = summation();
console.log(summationWithMemo(100));
console.log(summationWithMemo(100));

// console.log(summation(100));
// console.log(summation(100));